#include "stdafx.h"
#include "tzUtil.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

BOOL tzutil::GetFilePath(IN LPCTSTR lpszFileFullPath, OUT LPTSTR lpszFilePath)
{
	if ( !lpszFileFullPath || !lpszFilePath )
	{
		return FALSE;
	}

	// return null string if filepath is null.
	if ( lpszFileFullPath[0] == '\0')
	{
		lpszFilePath[0] = 0;
		return TRUE;
	}

	_tcscpy(lpszFilePath, lpszFileFullPath);

	// Find the last '\' character in filepath.
	LPTSTR pos = NULL, temppos = NULL;
	pos = lpszFilePath;
	temppos = _tcsstr(lpszFilePath, _T("\\"));
	while (temppos)
	{
		pos = temppos;
		temppos = _tcsstr(pos+1, _T("\\"));
	}

	*pos = 0;

	return TRUE;
}

BOOL tzutil::GetFileName(IN LPCTSTR lpszFileFullPath, OUT LPTSTR lpszFileName)
{
	if ( !lpszFileFullPath || !lpszFileName )
	{
		return FALSE;
	}

	// return null string if filepath is null.
	if ( lpszFileFullPath[0] == '\0')
	{
		lpszFileName[0] = 0;
		return TRUE;
	}



	// Find the last '\' character in filepath.
	LPCTSTR temppos = _tcsrchr(lpszFileFullPath, _T('\\'));
	if (temppos)
	{
		_tcscpy(lpszFileName, temppos+1);
	}
	else
	{
		_tcscpy(lpszFileName, lpszFileFullPath);
	}


	return TRUE;
}

BOOL tzutil::GetFileExtentName(IN LPCTSTR lpszFileFullPath, OUT LPTSTR lpszFileExtentName)
{
	if ( !lpszFileFullPath || !lpszFileExtentName )
	{
		return FALSE;
	}

	// return null string if filepath is null.
	if ( lpszFileFullPath[0] == '\0')
	{
		lpszFileExtentName[0] = 0;
		return TRUE;
	}



	// Find the last '.' character in filepath.
	LPCTSTR temppos = _tcsrchr(lpszFileFullPath, _T('.'));
	if (temppos)
	{
		_tcscpy(lpszFileExtentName, temppos+1);
	}
	else
	{
		lpszFileExtentName[0] = 0;
	}


	return TRUE;
}


